<!doctype html>
<html xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"><head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta name="viewport" content="width=device-width,initial-scale=1">
	<meta name="description" content="A fully featured admin theme which can be used to build CRM, CMS, etc.">
	<meta name="author" content="Coderthemes">
	
	<script src="/static/plugins/lodop/LodopFuncs.js"></script>
	<object  id="LODOP_OB" classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width=0 height=0> 
       <embed id="LODOP_EM" type="application/x-print-lodop" width=0 height=0></embed>
	</object>
</head>
<body>

	<button type="button" onclick="doReview()">打印PDF</button>
	<script>
	//var LODOP=getLodop(document.getElementById('LODOP_OB'),document.getElementById('LODOP_EM'));
	var LODOP;
	
	function doReview() {
		var strURL="http://localhost:8089/static/img/TCZX-230215-1005.pdf";
		  LODOP=getLodop();
		  LODOP.PRINT_INIT("测试PDF打印功能");
		  LODOP.ADD_PRINT_PDF(0,0,"500","300",demoDownloadPDF(strURL));
		  LODOP.PREVIEW();
	}
	

    function demoGetBASE64(dataArray) {
        var digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
        var strData = "";
        for (var i = 0, ii = dataArray.length; i < ii; i += 3) {
            if (isNaN(dataArray[i])) break;
            var b1 = dataArray[i] & 0xFF, b2 = dataArray[i + 1] & 0xFF, b3 = dataArray[i + 2] & 0xFF;
            var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
            var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
            var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
            strData += digits.substring(d1, d1 + 1) + digits.substring(d2, d2 + 1) + digits.substring(d3, d3 + 1) + digits.substring(d4, d4 + 1);
        }
        return strData;
    }

    function demoCreatePrinterList() {         
          setTimeout(" CreatePrinterList();","500");  //500毫秒后执行CreatePrinterList()函数,等待网页内容加载完毕。 
       
    }

    function demoOpenLocalPDFfile() {
        document.getElementById('text01').value='正在打开，请稍等...';
        var fileInput = document.createElement('input');
        fileInput.setAttribute('type', 'file');
        fileInput.setAttribute('accept', 'application/pdf');
        document.body.appendChild(fileInput);
        fileInput.onchange=function(evt) {
                var file = evt.target.files[0];
                var fileReader = new FileReader();
                fileReader.onload = function(evt) {
                        document.getElementById('text01').value = demoGetBASE64(new Uint8Array(evt.target.result));
                        fileInput.parentNode.removeChild(fileInput);
                };
                fileReader.readAsArrayBuffer(file);
        };
        fileInput.click();
    }

    function demoDownloadPDF(url){
        if (!(/^https?:/i.test(url))) return;
        if (window.XMLHttpRequest) var xhr = new XMLHttpRequest(); else var xhr = new ActiveXObject("MSXML2.XMLHTTP");
        xhr.open('GET',url,false); //同步方式
        if (xhr.overrideMimeType)
        try{
              xhr.responseType = 'arraybuffer';
              var arrybuffer=true;
        }catch(err){
              xhr.overrideMimeType('text/plain; charset=x-user-defined');
        }
        xhr.send(null);
        var data = xhr.response || xhr.responseBody;
        if (typeof Uint8Array !== 'undefined') {
              if (arrybuffer) var dataArray = new Uint8Array(data); else {
                    var dataArray = new Uint8Array(data.length);
                    for (var i = 0; i < dataArray.length; i++) {dataArray[i] = data.charCodeAt(i);}
              }
        } else
        var dataArray = VBS_BinaryToArray(data).toArray(); //兼容IE低版本
        return demoGetBASE64(dataArray);
    }
    
    function CreatePrinterList(){
	    if (document.getElementById('Select01').innerHTML!="") return;
		LODOP=getLodop(); 
		var iPrinterCount=LODOP.GET_PRINTER_COUNT();
		for(var i=0;i<iPrinterCount;i++){

   			var option=document.createElement('option');
   			option.innerHTML=LODOP.GET_PRINTER_NAME(i);
   			option.value=i;
			document.getElementById('Select01').appendChild(option);
		};	
	};

	</script>
</body>
</html>